"use strict";
var fs = require('fs');
// 回调函数形式
function getXiaoQiaoInfo(filePath, callback) {
    fs.readFile(filePath, function (err, data) {
        if (err) {
            callback(err);
        }
        else {
            // const error = new Error('警告')
            callback(JSON.parse(data.toString()));
        }
    });
}
getXiaoQiaoInfo('./assets/15-promise.json', function (res) {
    console.log('res', res);
});
// promise形式
function getXiaoQiaoInfoAsync(filePath) {
    return new Promise(function (res, rej) {
        fs.readFile(filePath, function (err, data) {
            if (err) {
                rej(err);
            }
            else {
                res(data);
            }
        });
    });
}
getXiaoQiaoInfoAsync('./assets/15-promise.json').then(function (res) {
    var data = JSON.parse(res.toString());
    console.log('data', data);
});
// promise.all()
// 通过 setTimeout 模 拟向 服务器 拉 取 数据
function fethUserInfo(userId) {
    return new Promise(function (resolve) {
        setTimeout(function () {
            resolve({ userId: userId });
        }, 1000);
    });
}
function fethCartInfo(userId) {
    return new Promise(function (resolve) {
        setTimeout(function () {
            resolve({ userId: userId });
        }, 1200);
    });
}
function fethGoodInfo(goodId) {
    return new Promise(function (resolve) {
        setTimeout(function () {
            resolve({ goodId: goodId });
        }, 1500);
    });
}
Promise.all([fethUserInfo(" 1"), fethCartInfo(" 2"), fethGoodInfo(" 233")])
    .then(function (res) { console.log(res); });
